﻿using ApplicationModels.A05.Reports;
using AutoMapper;
using Commons.Enums;
using Commons.Helpers;
using Commons.Responses;
using EntityModels.E05.Reports;
using IApplicationServices;
using IRepositories;
using System.Linq.Expressions;

namespace ApplicationService
{
    public class PhotographReportService : BaseApplicationService<int, Report, ReportAM>, IPhotographReportService
    {
        private IPhotographReportRepository reportRepository;
        public PhotographReportService(IPhotographReportRepository repository, IMapper mapper) : base(repository, mapper)
        {
            reportRepository = repository;
        }

        public async Task<MessageResponse> ReportExamine(int id, ReportStatusEnum status)
        {
            var data = await Repository.GetAsync(id);
            if (data == null)
            {
                throw new CustomException("id不存在!");
            }
            data.Examine(status);
            return await Repository.UpdateAsync(data);
        }

        public override async Task<DatasResponse<ReportAM>> GetBySelectAsync(int pageIndex, int pageSize, Expression<Func<Report, bool>> predicate)
        {
            var bos =  (await reportRepository.GetBySelectAsync(pageIndex, pageSize, predicate)).Datas;
            var apibos = Mapper.Map<List<ReportAM>>(bos);
            return new DatasResponse<ReportAM>(apibos);

        }
    }
}
